<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .odiv1{
            width: 100px;
            height: 100px;
            background-color: red;
        }
        .odiv2{
            background-color: yellow;
        }
    </style>
</head>
<body>
<div id='box' class = 'odiv1'></div>
</body>
<script>
    var box = document.getElementById('box')

    // box.onclick = function () {
    //     var cls = this.getAttribute('class')
    //     console.log(cls)
    //     this.setAttribute('class',cls + ' odiv2')
    // }

     box.onclick = function () {
         if(this.classList.contains('odiv2')){
               this.classList.remove('odiv2')
         }else{
            this.classList.add('odiv2')
         }
    }
</script>


</html>